import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

public class GameQueue {
	
	class Update {
		 int id;
         String username;
         char[] board;
         
         public Update(int id, String user, char[] updates) { 
        	 this.id = id;
        	 username = user;
        	 board = updates;
         }
	}
	
	 private BlockingQueue<Update> gamequeue;
     
     public GameQueue() { 
    	 gamequeue = new ArrayBlockingQueue<Update>(100000);
     }
     
     public boolean hasUpdate() { 
    	 return !gamequeue.isEmpty();
     }
     
 	public char[] process(String s) { 
 		char[] ret;
 		if(s.length() > 1)
 			s = s.substring(1, s.length() - 1);
 		String[] t = s.split(", ");
 		ret = new char[t.length];
 		
 		for(int i = 0; i < t.length; i++) { 
 			if(t[i].length() > 0)
 				ret[i] = t[i].charAt(t[i].length() - 1);
 		}
 		
 		return ret;
 	}
     
     public void add(int b, String usr, String board) { 
    	 char[] update;
    	 if(board.trim().equals("START"))
    	 {
    		update = null; 
    	 } else
    	 {
    		 board = board.substring(1, board.length() - 1);
    		 update = process(board);
    	 }
	     gamequeue.add(new Update(b, usr, update));
     }	 
     
     public Update getMessage() { 
             return gamequeue.poll();
     }
     
     public void clearQueue() { 
             gamequeue.clear();
     }

}